<script>
	import {
		sendRequest
	} from './util/api.js'
	import api from './util/api.js'
	import wsRequest from "@/util/websocket.js"
	export default {
		
		onUniNViewMessage: function(e) {
			console.log(e)
			if (e.data.code == 200) {
				appOnLaunch()
			}
		},
		onLaunch: function() {
			console.log('App Launch')
			
			appOnLaunch()
			uni.$on('setData', (res) => {
				console.log('接受的数据：', res)
				if(res != null){
					uni.showTabBarRedDot({ //显示
						index: 3, //tabbar下标
					})
				}
			})
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		//全局数据变量定义
		globalData:{
			//关注消息列表
			addUserList: [],
			//聊天消息列表
			chatList: [],
		},

	}
	export function appOnLaunch() {
		sendRequest({
			url: "/users/token",
			method: 'POST',
			success: (res) => {
				if (res.data.code == 200) {
					let websocket = new wsRequest(api.WS_URL + '/WebSocket/' + uni.getStorageSync('uuId'),
						10000)
					Vue.prototype.$socket = websocket
				} else {
					uni.removeStorage({
						key: 'token',
						success: function(res) {
							console.log('user_token移除成功');
						}
					});
					uni.removeStorage({
						key: 'uuId',
						success: function(res) {
							console.log('user_uuId移除成功');
						}
					});
					uni.removeStorage({
						key: 'nickname',
						success: function(res) {
							console.log('user_nickname移除成功');
						}
					});
					uni.removeStorage({
						key: 'icon',
						success: function(res) {
							console.log('user_icon移除成功');
						}
					});
				}

			}
		});
	}
</script>

<style lang="scss">
	
	/* #ifndef APP-NVUE */
	/*每个页面公共css */
	@import "uview-ui/index.scss";
	@import '@/static/customicons.css';

	@font-face {
		font-family: my-font;
		src: url('~@/static/zit/zit.ttf');
	}

	// 设置整个项目的背景色
	page {
		background-color: #f2f3f7;
	}
	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}
	/* #endif */
	.example-info {
		font-size: 14px;
		color: #333;
		padding: 10px;
	}
	
</style>
